package com.yesep.learn.netty.tcp.protocol.common;

/**
 * @Description: 执行结果定义表
 */
public enum EXE_RTN {

	SUCCESS(1, "执行成功", ""), ERROR(2, "执行失败，但不知道原因", ""), CMD_ERROR(3, "命令请求条件错误", ""), 
	TIMEOUT(4, "通讯超时", ""), BUSY(5, "系统繁忙不能执行", ""), FAULT(6, "系统故障", ""),
	 MSG_ERROR(98, "报文格式错误", ""),NORMAL(99, "正常", ""), NODATA(100, "没有数据", "");

	private Integer code;//编号
	private String message;//描述
	private String remark;//备注

	private EXE_RTN(Integer code, String message, String remark) {
		this.code = code;
		this.message = message;
		this.remark = remark;
	}

	public Integer getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	public String getRemark() {
		return remark;
	}

	@Override
	public String toString() {
		return this.name() + "(" + this.code + " | " + this.message + " | " + this.remark + ")";
	}

	/**
	 * 根据code获取message
	 * @param code
	 * @return
	 */
	public static EXE_RTN get(int code) {
		//通过enum.values()获取所有的枚举值
		for (EXE_RTN e : EXE_RTN.values()) {
			//通过enum.get获取字段值
			if (e.getCode() == code) {
				return e;
			}
		}
		return null;
	}
}
